package com.ruoyi.web.controller;
import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.JjmOrder;
import com.ruoyi.web.service.IJjmOrderService;
import com.ruoyi.web.domain.vo.JjmOrderVO;
import com.ruoyi.web.utils.pageutils.PaginationUtil;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2024-07-16
 */
@CrossOrigin
@RestController
@RequestMapping("/web/order")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class JjmOrderController extends BaseController
{
    private final IJjmOrderService jjmOrderService;

    /**
     * 获取订单列表的分页数据
     * 通过HTTP GET请求来获取订单的分页列表信息。该方法接收一个订单对象和分页参数，
     * 并返回一个包含分页信息的TableDataInfo对象。
     * @param jjmOrder 订单对象，用于查询订单信息
     * @param pageNum 分页查询的页码
     * @param pageSize 分页查询的每页大小
     * @return 返回包含订单列表分页信息的TableDataInfo对象
     */
    @GetMapping("/list")
    public TableDataInfo list(JjmOrder jjmOrder, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize) {
        // 根据订单对象获取订单列表
        List<JjmOrderVO> page = jjmOrderService.orderList(jjmOrder);
        // 根据订单列表、页码和每页大小获取分页信息，并返回
        return PaginationUtil.getPageInfo(page, pageNum, pageSize);
    }


    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(JjmOrder jjmOrder) {
        List<JjmOrder> list = jjmOrderService.list(new QueryWrapper<JjmOrder>(jjmOrder));
        ExcelUtil<JjmOrder> util = new ExcelUtil<JjmOrder>(JjmOrder.class);
        util.exportExcel(list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(jjmOrderService.getById(id));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JjmOrder jjmOrder) {
        return toAjax(jjmOrderService.add(jjmOrder));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JjmOrder jjmOrder) {
        return toAjax(jjmOrderService.updateById(jjmOrder));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(jjmOrderService.removeByIds(Arrays.asList(ids)));
    }
}
